﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using Microsoft.Office.Core;

namespace MyStylesTemplate
{
  public partial class MyStylesRibbon : OfficeRibbon
  {
    /// <summary>
    /// Initializes the elements of the ribbon.
    /// </summary>
    public MyStylesRibbon()
    {
      InitializeComponent();
    }

    /// <summary>
    /// Responds to the Click event of all buttons on this ribbon.
    /// </summary>
    /// <param name="sender">Button sending the event.</param>
    /// <param name="e">Event arguments.</param>
    private void RibbonButton_Click(object sender, RibbonControlEventArgs e)
    {
      RibbonButton control = sender as RibbonButton;
      if (control != null) ApplyStyle(control.Tag.ToString());
    }

    /// <summary>
    /// Applies the specified style on the current selection.
    /// </summary>
    /// <param name="styleName">Name of the style to apply.</param>
    private void ApplyStyle(string styleName)
    {
      object styleIndex = styleName;
      object style = Globals.ThisDocument.Styles.get_Item(ref styleIndex);
      Globals.ThisDocument.ThisApplication.Selection.set_Style(ref style);
    }
  }
}
